//
//  FinanceReqModel.m
//  BrushFace
//
//  Created by 樊娜娜 on 15/12/23.
//  Copyright © 2015年 Zzz. All rights reserved.
//

#import "FinanceReqModel.h"

@implementation FinanceReqModel
-(void)loadSceneModel{
    [super loadSceneModel];
}
//首页理财列表
- (void)hope_listFriendHopeWithCurPage:(int)curPage andRPP:(int)rpp andCB:(void (^)(NSMutableArray *resultArray))CB{
    
    NSDictionary *params = @{@"curPage":[NSString stringWithFormat:@"%d",curPage],
                             @"rPP":[NSString stringWithFormat:@"%d",rpp]
                             };
    NSString *requestStr = [NSString stringWithFormat:@"%@/hope/listfriendhope.json",SERVICE_ADRESS];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager GET:requestStr parameters:params success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        NSError *error;
        NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&error];
        CB([jsonObject objectForKey:@"data"]);
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        
    }];
}
//获取出借优惠券列表
- (void)hope_getBorrowCouponsListAndCB:(void (^)(id output))CB{
    NSString *requestStr = [NSString stringWithFormat:@"%@/hope/getborrowcouponslist.json",SERVICE_ADRESS];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
    [manager GET:requestStr parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        NSDictionary *jsondict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        CB(jsondict);
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        
    }];
    
}

//出借时获取预计收益列表
- (void)hope_genIncomeWithHopeId:(NSString *)hopeid andIsFace:(NSString *)isface andAmount:(NSString *)amount andConpousId:(NSString *)conpousid andCB:(void (^)(id output))CB{
    NSString *requestStr = [NSString stringWithFormat:@"%@/hope/genincome.json",SERVICE_ADRESS];
    NSDictionary *params = @{@"hopeid":hopeid,
                             @"amount":amount,
                             @"couponsid":conpousid,
                             @"isface":isface};
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
    [manager GET:requestStr parameters:params success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        NSDictionary *jsondict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        CB(jsondict);
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        
    }];
}

/**
 *  出借提交订单
 */
- (void)hope_investHopeWithHopeID:(NSString *)hopeID andAmount:(NSString *)amount andIsFace:(NSString *)isface andCouponsid:(NSString *)couponsid andNote:(NSString *)note andCB:(void(^)(id output))CB{
    NSString *requestStr = [NSString stringWithFormat:@"%@/hope/investhope.json",SERVICE_ADRESS];
    NSDictionary *params = @{@"hopeid":hopeID,
                             @"amount":amount,
                             @"isFace":isface,
                             @"channel":@"1",
                             @"note":[self replayRequestStr:note],
                             @"couponsid":couponsid,
                             @"flag":@"1"
                             };
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
    [manager GET:requestStr parameters:params success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        NSDictionary *jsondict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        CB(jsondict);
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        
    }];

}
- (NSString *)replayRequestStr:(NSString *)baseStr{
    NSMutableString *reasonMutable = [[NSMutableString alloc] init];
    for (int i=0; i<baseStr.length; i++) {
        UniChar b = [baseStr characterAtIndex:i];
        NSString *str = [ [NSString alloc] initWithFormat:@"%x",b];
        while (str.length<4) {
            str = [NSString stringWithFormat:@"0%@",str];
        }
        [reasonMutable appendString:str];
    }
    return reasonMutable;
}
@end
